.class public Lcom/melesta/payment/inapp/InAppSystem;
.super Ljava/lang/Object;
.source "InAppSystem.java"

# interfaces
.implements Lcom/melesta/payment/interfaces/ISystem;


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;
    }
.end annotation


# static fields
.field private static final DB_INITIALIZED:Ljava/lang/String; = "db_initialized"

.field static final SYSTEM_NAME:Ljava/lang/String; = "inapp"

.field private static final TAG:Ljava/lang/String; = "payment-inapp"


# instance fields
.field private defaultListener:Lcom/melesta/payment/interfaces/IListener;

.field private mBillingService:Lcom/google/BillingService;

.field private mContext:Landroid/content/Context;

.field private mDungeonsPurchaseObserver:Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;

.field private mHandler:Landroid/os/Handler;

.field private final mPayloadContents:Ljava/lang/String;


# direct methods
.method public constructor <init>()V
    .locals 1

    .prologue
    .line 46
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 72
    const/4 v0, 0x0

    iput-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mPayloadContents:Ljava/lang/String;

    .line 92
    return-void
.end method

.method static synthetic access$000(Lcom/melesta/payment/inapp/InAppSystem;)Landroid/content/Context;
    .locals 1
    .parameter "x0"

    .prologue
    .line 46
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mContext:Landroid/content/Context;

    return-object v0
.end method

.method static synthetic access$100(Lcom/melesta/payment/inapp/InAppSystem;)V
    .locals 0
    .parameter "x0"

    .prologue
    .line 46
    invoke-direct {p0}, Lcom/melesta/payment/inapp/InAppSystem;->restoreDatabase()V

    return-void
.end method

.method static synthetic access$200(Lcom/melesta/payment/inapp/InAppSystem;)Lcom/melesta/payment/interfaces/IListener;
    .locals 1
    .parameter "x0"

    .prologue
    .line 46
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->defaultListener:Lcom/melesta/payment/interfaces/IListener;

    return-object v0
.end method

.method private restoreDatabase()V
    .locals 4

    .prologue
    const/4 v3, 0x0

    .line 269
    iget-object v2, p0, Lcom/melesta/payment/inapp/InAppSystem;->mContext:Landroid/content/Context;

    check-cast v2, Landroid/app/Activity;

    invoke-virtual {v2, v3}, Landroid/app/Activity;->getPreferences(I)Landroid/content/SharedPreferences;

    move-result-object v1

    .line 271
    .local v1, prefs:Landroid/content/SharedPreferences;
    const-string v2, "db_initialized"

    invoke-interface {v1, v2, v3}, Landroid/content/SharedPreferences;->getBoolean(Ljava/lang/String;Z)Z

    move-result v0

    .line 272
    .local v0, initialized:Z
    if-nez v0, :cond_0

    .line 273
    iget-object v2, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    invoke-virtual {v2}, Lcom/google/BillingService;->restoreTransactions()Z

    .line 277
    :cond_0
    return-void
.end method


# virtual methods
.method public buy(Lcom/melesta/payment/inapp/InAppRequest;)V
    .locals 6
    .parameter "request"

    .prologue
    .line 283
    invoke-virtual {p1}, Lcom/melesta/payment/inapp/InAppRequest;->getName()Ljava/lang/String;

    move-result-object v1

    .line 284
    .local v1, mItemName:Ljava/lang/String;
    invoke-virtual {p1}, Lcom/melesta/payment/inapp/InAppRequest;->getSku()Ljava/lang/String;

    move-result-object v2

    .line 285
    .local v2, mSku:Ljava/lang/String;
    invoke-virtual {p1}, Lcom/melesta/payment/inapp/InAppRequest;->getCountPerItem()I

    move-result v0

    .line 287
    .local v0, mCountPerItem:I
    const-string v3, "payment-inapp"

    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    const-string v5, "buying: "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    const-string v5, " sku: "

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-static {v3, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 289
    iget-object v3, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    iget-object v4, p0, Lcom/melesta/payment/inapp/InAppSystem;->mPayloadContents:Ljava/lang/String;

    invoke-virtual {v3, v2, v4}, Lcom/google/BillingService;->requestPurchase(Ljava/lang/String;Ljava/lang/String;)Z

    move-result v3

    if-nez v3, :cond_0

    .line 290
    invoke-static {}, Lcom/melesta/payment/PaymentManager;->getInstance()Lcom/melesta/payment/PaymentManager;

    move-result-object v3

    new-instance v4, Lcom/melesta/payment/inapp/InAppResponse;

    invoke-direct {v4}, Lcom/melesta/payment/inapp/InAppResponse;-><init>()V

    invoke-virtual {v4, v1}, Lcom/melesta/payment/inapp/InAppResponse;->setName(Ljava/lang/String;)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    invoke-virtual {v4, v2}, Lcom/melesta/payment/inapp/InAppResponse;->setSku(Ljava/lang/String;)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    invoke-virtual {v4, v0}, Lcom/melesta/payment/inapp/InAppResponse;->setCountPerItem(I)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    sget-object v5, Lcom/melesta/payment/inapp/InAppResponse$Status;->ERROR:Lcom/melesta/payment/inapp/InAppResponse$Status;

    invoke-virtual {v4, v5}, Lcom/melesta/payment/inapp/InAppResponse;->setStatus(Lcom/melesta/payment/inapp/InAppResponse$Status;)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    sget-object v5, Lcom/google/Consts$ResponseCode;->RESULT_BILLING_UNAVAILABLE:Lcom/google/Consts$ResponseCode;

    invoke-virtual {v5}, Lcom/google/Consts$ResponseCode;->ordinal()I

    move-result v5

    invoke-virtual {v4, v5}, Lcom/melesta/payment/inapp/InAppResponse;->setErrorCode(I)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    iget-object v5, p0, Lcom/melesta/payment/inapp/InAppSystem;->defaultListener:Lcom/melesta/payment/interfaces/IListener;

    invoke-virtual {v4, v5}, Lcom/melesta/payment/inapp/InAppResponse;->setListener(Lcom/melesta/payment/interfaces/IListener;)Lcom/melesta/payment/inapp/InAppResponse;

    move-result-object v4

    invoke-virtual {v3, v4}, Lcom/melesta/payment/PaymentManager;->postResponse(Lcom/melesta/payment/interfaces/IResponse;)V

    .line 301
    :cond_0
    return-void
.end method

.method public get(Ljava/lang/String;)Ljava/lang/Object;
    .locals 1
    .parameter "property"

    .prologue
    .line 335
    const/4 v0, 0x0

    return-object v0
.end method

.method public getDefaultListener()Lcom/melesta/payment/interfaces/IListener;
    .locals 1

    .prologue
    .line 339
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->defaultListener:Lcom/melesta/payment/interfaces/IListener;

    return-object v0
.end method

.method public getName()Ljava/lang/String;
    .locals 1

    .prologue
    .line 310
    const-string v0, "inapp"

    return-object v0
.end method

.method public getRequestBuilder()Lcom/melesta/payment/interfaces/IRequestBuilder;
    .locals 1

    .prologue
    .line 305
    new-instance v0, Lcom/melesta/payment/inapp/InAppRequestBuilder;

    invoke-direct {v0, p0}, Lcom/melesta/payment/inapp/InAppRequestBuilder;-><init>(Lcom/melesta/payment/inapp/InAppSystem;)V

    return-object v0
.end method

.method public onActivityResult(Landroid/content/Context;IILandroid/content/Intent;)Z
    .locals 1
    .parameter "context"
    .parameter "requestCode"
    .parameter "resultCode"
    .parameter "data"

    .prologue
    .line 349
    const/4 v0, 0x0

    return v0
.end method

.method public onCreate(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 2
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 221
    invoke-static {}, Lcom/google/BillingService;->setConfigured()V

    .line 223
    iput-object p2, p0, Lcom/melesta/payment/inapp/InAppSystem;->mHandler:Landroid/os/Handler;

    .line 224
    iput-object p1, p0, Lcom/melesta/payment/inapp/InAppSystem;->mContext:Landroid/content/Context;

    .line 226
    new-instance v0, Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;

    iget-object v1, p0, Lcom/melesta/payment/inapp/InAppSystem;->mHandler:Landroid/os/Handler;

    invoke-direct {v0, p0, v1}, Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;-><init>(Lcom/melesta/payment/inapp/InAppSystem;Landroid/os/Handler;)V

    iput-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mDungeonsPurchaseObserver:Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;

    .line 227
    new-instance v0, Lcom/google/BillingService;

    invoke-direct {v0}, Lcom/google/BillingService;-><init>()V

    iput-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    .line 228
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    invoke-virtual {v0, p1}, Lcom/google/BillingService;->setContext(Landroid/content/Context;)V

    .line 233
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mDungeonsPurchaseObserver:Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;

    invoke-static {v0}, Lcom/google/ResponseHandler;->register(Lcom/google/PurchaseObserver;)V

    .line 234
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    invoke-virtual {v0}, Lcom/google/BillingService;->checkBillingSupported()Z

    move-result v0

    if-nez v0, :cond_0

    .line 237
    :cond_0
    return-void
.end method

.method public onDestroy(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 1
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 257
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mBillingService:Lcom/google/BillingService;

    invoke-virtual {v0}, Lcom/google/BillingService;->unbind()V

    .line 259
    return-void
.end method

.method public onPause(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 0
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 317
    return-void
.end method

.method public onResume(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 0
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 323
    return-void
.end method

.method public onStart(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 1
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 244
    iget-object v0, p0, Lcom/melesta/payment/inapp/InAppSystem;->mDungeonsPurchaseObserver:Lcom/melesta/payment/inapp/InAppSystem$InAppPurchaseObserver;

    invoke-static {v0}, Lcom/google/ResponseHandler;->register(Lcom/google/PurchaseObserver;)V

    .line 245
    return-void
.end method

.method public onStop(Landroid/content/Context;Landroid/os/Handler;)V
    .locals 0
    .parameter "context"
    .parameter "handler"

    .prologue
    .line 253
    return-void
.end method

.method public purchaseProcessed(Lcom/melesta/payment/PaymentTransaction;)V
    .locals 0
    .parameter "pt"

    .prologue
    .line 354
    return-void
.end method

.method public set(Ljava/lang/String;Ljava/lang/Object;)Lcom/melesta/payment/inapp/InAppSystem;
    .locals 1
    .parameter "property"
    .parameter "value"

    .prologue
    .line 327
    const-string v0, "openkey"

    invoke-virtual {v0, p1}, Ljava/lang/String;->equals(Ljava/lang/Object;)Z

    move-result v0

    if-eqz v0, :cond_0

    .line 328
    invoke-virtual {p2}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v0

    invoke-static {v0}, Lcom/google/Security;->setPublicKey(Ljava/lang/String;)V

    .line 330
    :cond_0
    return-object p0
.end method

.method public bridge synthetic set(Ljava/lang/String;Ljava/lang/Object;)Lcom/melesta/payment/interfaces/ISystem;
    .locals 1
    .parameter "x0"
    .parameter "x1"

    .prologue
    .line 46
    invoke-virtual {p0, p1, p2}, Lcom/melesta/payment/inapp/InAppSystem;->set(Ljava/lang/String;Ljava/lang/Object;)Lcom/melesta/payment/inapp/InAppSystem;

    move-result-object v0

    return-object v0
.end method

.method public setDefaultListener(Lcom/melesta/payment/interfaces/IListener;)Lcom/melesta/payment/inapp/InAppSystem;
    .locals 0
    .parameter "defaultListener"

    .prologue
    .line 343
    iput-object p1, p0, Lcom/melesta/payment/inapp/InAppSystem;->defaultListener:Lcom/melesta/payment/interfaces/IListener;

    .line 344
    return-object p0
.end method
